package com.example.cinemasystemv2.repository;

import com.example.cinemasystemv2.entity.ScreeningRoom;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;

@Repository
public interface ScreeningRoomRepository extends JpaRepository<ScreeningRoom, Long> {
    
    Optional<ScreeningRoom> findByName(String name);
    
    @Query("SELECT sr FROM ScreeningRoom sr WHERE sr.name LIKE %:keyword%")
    List<ScreeningRoom> searchRooms(@Param("keyword") String keyword);
    
    boolean existsByName(String name);
    
    @Query("SELECT COUNT(sr) FROM ScreeningRoom sr")
    long countAllRooms();
    
    @Query("SELECT SUM(sr.numRows * sr.seatsPerRow) FROM ScreeningRoom sr")
    Long getTotalSeats();
}